define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Util = {};
	Util.getGroupId = function() {
		var str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		var groupId = "";
		var random;
		for (var i = 0; i < 4; i++) {
			random = Math.ceil(Math.random() * 52);
			groupId += str.slice(random - 1, random);
		}
		return groupId;
	};

	Util.sort = function(arr,key) {
		var newArr = [];
		var orderBy = null;
		arr.forEach(function(item,index){
			if(item["fkey"] == key){
				orderBy = item["fvalue"];
			}
		});
		if(orderBy){
			arr.forEach(function(item,index){
				for(var i =0 ;i<orderBy.length;i++){
					if(item["fkey"] == orderBy[i].key){
						item.index = orderBy[i].index;
						newArr.push(item);
					}
				}
			});
			for (var j = 0; j < newArr.length - 1; j++) {
				for (var i = 0; i < newArr.length - 1 - j; i++) {
					if (newArr[i].index > newArr[i+1].index) {
						var temp = newArr[i];
						newArr[i] = newArr[i + 1];
						newArr[i + 1] = temp;
					}
				}
			}
			return newArr;
		}else{
			return arr;
		}
		
	};
	return Util;
});